[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
brk() Change Data-Segment Space Allocation
#include <alloc.h>
int brk(endds);
void *endds; New ending address
brk() changes the space allocated to the data segment of a calling
program by resetting the program's 'break value'--the address of the
first location past the end of the data segment. brk() sets the
'break value' to 'endds'. As the break value increases, so does the
amount of allocated space.
Returns: 0, if successful. If the function fails, -1 is
returned and 'errno' (defined in <errno.h>) is set to
ENOMEM, not enough memory.
Notes: If an attempt is made to allocate more space than is
allowed, brk() fails and the space allocated to the
data segment remains unchanged.
-------------------------------- Example ---------------------------------
#include <alloc.h> /* for brk and sbrk */
#include <stdio.h> /* for printf */
main()
{
char *start;
start = sbrk(5000); /* allocates 5000 bytes
& returns old break value */
if (start == (char*)-1)
printf("Not enough memory\n");
else { /* allocates 2000 more bytes */
if (sbrk(2000) == (char*)-1)
printf("Not enough memory\n");
brk(start); /*deallocates both blocks */
}
}
See Also:
coreleft()
sbrk()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson